﻿using jlynet.core.Library;
using jlynet.core.notebook.util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace jlynet.core.notebook.myform
{
    public partial class RecoverPasswordForm : Form
    {

        public RecoverPasswordForm()
        {
            InitializeComponent();
            this.MinimizeBox = false;  //去掉最小化
            this.MaximizeBox = false;  //去掉最大化
            this.Load += (s, e) =>{
                DataView dv = MySQLiteHelper.SelectDataView("select * from userInfoTable where id_= ?;", new SQLiteParameter[] { new SQLiteParameter("id_", "1") });
                if (dv!=null)
                {
                    DataRowView row = dv[0];
                    string problem = row["problem"] != DBNull.Value ? row["problem"].ToString() : "";
                    this.textBox_problem.Text = problem;

                    string answer = row["answer"] != DBNull.Value ? row["answer"].ToString() : "";
                }

            };

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataView dv = MySQLiteHelper.SelectDataView("select * from userInfoTable where id_= ?;", new SQLiteParameter[] { new SQLiteParameter("id_", "1") });
            if (dv != null)
            {
                DataRowView row = dv[0];
                string problem = row["problem"] != DBNull.Value ? row["problem"].ToString() : "";
                string answer = row["answer"] != DBNull.Value ? row["answer"].ToString() : "";
                if (problem.Equals(this.textBox_problem.Text) && answer.Equals(this.textBox_answer.Text))
                {
                    string password = row["password"] != DBNull.Value ? row["password"].ToString() : "";
                    string password_ = DESEncrypt.Decrypt(password, Constant.DES_KEY);
                    MessageBox.Show(String.Format("您的密码为{0}请妥善保管！", password_), "找回密码提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                }
                else
                {
                    MessageBox.Show("提示密码问题答案回答错误！");
                }
            }

        }
    }
}
